package com.yanqu.road.server.logic.recharge.limit.activity;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.tongbing.config.TongBingConfig;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.entity.mall.LimitBuyResult;
import com.yanqu.road.logic.activity.chuhan.ChuHanConfig;
import com.yanqu.road.server.gameplayer.module.activity.tongbing.ChuHanModule;
import com.yanqu.road.server.gameplayer.module.activity.tongbing.TongBingModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.tongbing.ChuHanMgr;
import com.yanqu.road.server.manger.activity.tongbing.TongBingMgr;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.utils.date.DateHelper;

public class ChuHanActivityMallLimit extends BaseActivityMallLimit{
    public ChuHanActivityMallLimit(long userId, MallInfo mallInfo, ActivityInfo activityInfo) {
        super(userId, mallInfo, activityInfo);
    }

    @Override
    protected int activityCheck() {
        if(!ActivityMgr.activityInTime(activityInfo)){
            return GameErrorCode.E_ACTIVITY_NO_IN_TIME_CANNOT_BUY;
        }
        if(activityInfo.getType() != eActivityType.ChuHanZB.getValue()){
            return GameErrorCode.E_ACTIVITY_NO_IN_TIME_CANNOT_BUY;
        }
        return 0;
    }

    @Override
    protected boolean isSystemUnLock() {
        return SystemOpenMgr.systemOpen(player, eSystemId.ChuHanZB.getValue());
    }

    @Override
    protected LimitBuyResult buyCountLimit() {
        return activityMallCountLimit(player);
    }

    @Override
    protected int logicCheck() {
        ChuHanConfig config = ChuHanMgr.getConfig();
        if (config == null) {
            return GameErrorCode.E_ACTIVITY_NO_FOUND;
        }
        if (!ActivityMgr.activityInShowTime(config.getActivityInfo())) {
            return GameErrorCode.E_ACTIVITY_NO_FOUND;
        }

        long stage1BeginTime = config.getStage1TimeList().get(0).get(0);
        long zeroTimeStamp = DateHelper.getZeroTimeStamp(stage1BeginTime);
        long now = System.currentTimeMillis();
        if (now < zeroTimeStamp) {
            return GameErrorCode.E_CHUHAN_NO_OPERATE_TIME;
        }
        // 是否有资格购买
        if (!player.getModule(ChuHanModule.class).hasCamp()) {
            return GameErrorCode.E_CHUHAN_NO_ABLE;
        }
        return 0;
    }
}
